#pragma once
#include<iostream>
#include<vector>
#include<stdbool.h>
using namespace std;

namespace hu
{
	template<size_t N>
	class bitset
	{
	public:
		bitset()
		{
			_a.resize(N / 32 + 1);
		}

		void set(const size_t& key)
		{
			size_t i = key / 32;
			size_t j = key % 32;

			_a[i] = _a[i] | (1 << j);
		}
		void reset(const size_t& key)
		{
			size_t i = key / 32;
			size_t j = key % 32;

			_a[i] = _a[i] & (~(1 << j));
		}

		bool test(const size_t& key)
		{
			size_t i = key / 32;
			size_t j = key % 32;
			return _a[i] & (1 << j);
		}
	private:
		vector<int> _a;
	};

	template<size_t N>
	class twobitset
	{
	public:
		void set(const size_t& key)
		{
			if (!b1.test(key) && !b2.test(key))
			{
				b2.set(key);
			}
			else if (!b1.test(key) && b2.test(key))
			{
				b1.set(key);
				b2.reset(key);
			}
		}

		void reset(const size_t& key)
		{
			if (!b1.test(key) && b2.test(key))
			{
				b2.reset(key);
			}
			else if (b1.test(key) && !b2.test(key))
			{
				b1.reset(key);
				b2.set(key);
			}
		}

		bool isonce(const size_t& key)
		{
			return !b1.test(key) && b2.test(key);
		}
	private:
		bitset<N> b1;
		bitset<N> b2;
	};
}
